<%@ page language="java"  pageEncoding="UTF-8" %>
<%@ page import="com.shopping.modean.*" %>
<%@ page import="com.shopping.service.*" %>
<%@ page import="java.util.*" %>

<%
	User u = (User)session.getAttribute("user");
	if(u == null) {
		out.println("You have not logged in!");
		return;
	}
	
    request.setCharacterEncoding("UTF-8");
    String action = request.getParameter("action");
    if(action != null && action.trim().equals("modifyUser")) {
	  String username = request.getParameter("username");
	  String phone = request.getParameter("phone");
	  String addr = request.getParameter("addr");
	  u.setUsername(username);
	  u.setPhone(phone);
	  u.setAddr(addr);

	  //TODO 后台检查数据准确性
	  UserService userService = new UserService();
	  userService.update(u);
	  
	  ////重定向到个人服务页面
	  response.sendRedirect("user_self_service.jsp");
  }

%>

<!DOCTYPE html>
<html>
<head>
  <title>修改个人信息</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="text/javascript" src="script/regcheckdata.js"></script>
</head>

<body>

  <form method="post" name="register" action="user_modify.jsp" onSubmit="return checkdata(this)">
    <input type="hidden" name="action" value="modifyUser" />
	<table class="tableborder" align="center" cellpadding="4" cellspacing="1" width="97%">
      <tbody>
        <tr>
          <td class="altbg1" width="21%"><span style="color:red">*</span>用户名:</td>
          <td class="altbg2">
            <input id="userid" name="username" size="25" maxlength="25" type="text" value=<%=u.getUsername() %> > 
            <span id="usermsg"></span>
          </td>
        </tr>
        <tr>
          <td class="altbg1">&#30005;&#35805;:</td>
          <td class="altbg2"><input name="phone" type="text" id="phone" size="25" value=<%=u.getPhone() %> ></td>
        </tr>
        <tr>
          <td class="altbg1" valign="top">送货地址:</td>
          <td class="altbg2"><textarea name="addr" cols="60" rows="5" id="addr"><%=u.getAddr() %></textarea></td>
        </tr>
        <tr>
          <td class="altbg1"></td>
          <td class="altbg2"><input name="regsubmit" value="修&nbsp;改" type="submit"></td>
        </tr>
      </tbody>
    </table>
    
  </form>
  
</body>
</html>